#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Author: Faker.Deng
Exercise after Chapter 1 Problem 9
"""


# Bool class
class Book(object):
    """Book class"""
    def __init__(self, name, author):
        self.__name = name
        self.__author = author
        self.__reader = "In library"
        self.__wait_list = []

    def __str__(self):
        return "<" + self.__name + "> " + self.__author

    def reset(self):
        self.__reader = "In library"
        self.__wait_list = []

    def get_name(self):
        return self.__name

    def get_author(self):
        return self.__author

    def get_bespeak(self):
        return self.__wait_list

    def get_reader(self):
        return self.__reader

    def add_bespeak(self, *wait_list):
        for i in range(len(wait_list)):
            self.__wait_list.append(wait_list[i])

    def add_reader(self, reader_name):
        if self.__reader == "In library":
            self.__reader = reader_name
        else:
            print("The book has been lent out!")

    def return_book(self):
        self.__reader = "In library"

    def del_bespeak(self, bespeak_name):
        self.__wait_list.remove(bespeak_name)

    def info(self):
        print("Book name:", self.__name)
        print("Author:", self.__author)
        print("Reader now:", self.__reader)
        print("Bespeak List:", self.__wait_list)


# Patron
class Patron(object):
    """Patron class"""
    def __init__(self, name):
        self.__name = name
        self.__book_num = 0
        self.__book_list = []

    def __str__(self):
        return self.__name

    def reset(self):
        self.__book_num = 0
        self.__book_list = []

    def get_name(self):
        return self.__name

    def get_book_num(self):
        return self.__book_num

    def get_book_list(self):
        return self.__book_list

    def borrow_book(self, *book_list):
        book_num = len(book_list)
        if book_num + self.__book_num > 3:
            print("Beyond the scope of books that can be borrowed!")
            return
        else:
            self.__book_num = self.__book_num + book_num
            for i in range(book_num):
                self.__book_list.append(book_list[i])

    def return_book(self, *book_list):
        book_num = len(book_list)
        self.__book_num = self.__book_num - book_num
        for i in range(book_num):
            self.__book_list.remove(book_list[i])

    def info(self):
        print("Patron:", self.__name)
        print("Number of borrowing books:", self.__book_num)
        print("Borrowing books list:", self.__book_list)


# Test book class
def test_book_class():
    """ Test book class"""
    book1 = Book(name="Harry Potter and the Philosopher's Stone", author="J. K. Rowling")
    book2 = Book(name="Harry Potter and the Chamber of Secrets", author="J. K. Rowling")
    print(book1)
    print(book2)
    book1.add_reader("ZhangSan")
    book1.add_reader("LiSi")
    book2.add_reader("LiSi")
    book1.add_bespeak("LiSi")
    book2.add_bespeak("ZhangSan", "WangWu")
    book1.info()
    book2.info()
    book1.return_book()
    book2.del_bespeak("ZhangSan")
    print(book1.get_reader())
    print(book2.get_bespeak())


# Test patron class
def test_patron_class():
    """Test patron class"""
    patron1 = Patron(name="ZhangSan")
    patron2 = Patron(name="LiSi")
    print(patron1)
    print(patron2)
    patron1.borrow_book("Harry Potter and the Philosopher's Stone",
                        "Harry Potter and the Chamber of Secrets")
    patron1.info()
    patron2.borrow_book("Harry Potter and the Philosopher's Stone",
                        "Harry Potter and the Chamber of Secrets",
                        "Harry Potter and the Prisoner of Azkaban",
                        "Harry Potter and the Goblet of Fire")
    patron2.borrow_book("Harry Potter and the Goblet of Fire")
    print(patron2.get_book_list())
    patron2.return_book("Harry Potter and the Goblet of Fire")
    patron2.info()


if __name__ == "__main__":
    test_book_class()
    test_patron_class()
